const cloud = require('wx-server-sdk');
const DBCONST = require('./const/dbConst.js');


// API 调用都保持和云函数当前所在环境一致
const env = cloud.DYNAMIC_CURRENT_ENV;
// 初始化cloud
cloud.init({ env });
const db = cloud.database({});

const db_account = db.collection(DBCONST.DB_ACCOUNT);
const db_credit = db.collection(DBCONST.DB_CREDIT);
const db_income = db.collection(DBCONST.DB_INCOME);

const getOpenid = () => {
  const { OPENID } = cloud.getWXContext();
  return OPENID;
}

module.exports = {
  db,
  getOpenid,
  db_account,
  db_credit,
  db_income,
  cloud
};